﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web;

namespace BIZ
{
   public class AdminFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Log("OnActionExecuting", filterContext.RouteData, filterContext.HttpContext);
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //Log("OnActionExecuted", filterContext.RouteData, filterContext.HttpContext);
        }

        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            //Log("OnResultExecuting", filterContext.RouteData, filterContext.HttpContext);
        }

        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            //Log("OnResultExecuted", filterContext.RouteData, filterContext.HttpContext);
        }

        private void Log(string methodName, RouteData routeData, HttpContextBase context)
        {
            //var controllerName = routeData.Values["controller"];
            //var actionName = routeData.Values["action"];
            if (HttpContext.Current.Session["cmsuser"] == null)
            {
                string url = "/member/login.html?from=/cms/index.html";
                Redirect(url);
            }
        }

        public static void Redirect(string url)
        {
            ScriptKit.WriteScript("window.top.location.href=\"" + url + "\";");
            if (null != HttpContext.Current)
            {
                HttpContext.Current.Response.End();
            }
        }

    }
}
